/**
 * 
 */
package com.lanswon.service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lanswon.common.enums.ArticleStatus;
import com.lanswon.dao.ArticleMapper;
import com.lanswon.entity.ArticleVO;

/**
 * @author lanswon
 *
 */
@Service
public class ArticleService {
	@Autowired
	private ArticleMapper articleMapper;

	public int addArticle(ArticleVO articleVO) {
		Date time = new Date();
		articleVO.setCreateTime(time);
		articleVO.setUpdateTime(time);
		articleVO.setArticleStatus(ArticleStatus.ARTICLE_STATUS_NOMAL.getCode());
		return articleMapper.insert(articleVO);
	}
	
	public int updateArticle(ArticleVO articleVO) {
		articleVO.setUpdateTime(new Date());
		return articleMapper.updateByPrimaryKey(articleVO);
	}

	public void deleteArticle(Long articleId) {
		articleMapper.deleteByPrimaryKey(articleId);
	}

	public Integer pageListCount(Map<String, Object> map){
		return articleMapper.selectArticlePageListCount(map);
	}
	
	public List<ArticleVO> pageList(Map<String, Object> map){
		return articleMapper.selectArticlePageList(map);
	}

	public ArticleVO findArticleById(Long articleId) {
		return articleMapper.selectByPrimaryKey(articleId);
	}
	
	/**
	 * 前一篇文章
	 */
	public ArticleVO findAheadArticle(Map<String, Object> map) {
		return articleMapper.selectAheadArticle(map);
	}

	/**
	 * 后一篇文章
	 */
	public ArticleVO findAfterArticle(Map<String, Object> map) {
		return articleMapper.selectAfterArticle(map);
	}

	public Integer findArticleCountByCondition(Map<String, Object> map) {
		return articleMapper.selectArticleCountByCondition(map);
	}

	public List<ArticleVO> findArticleByCondition(Map<String, Object> accessMap) {
		return articleMapper.selectArticleByCondition(accessMap);
	}

	
}
